require.config({
	paths : {
		"jquery" : "../jquery",
		"cookie" : "../jquery.cookie",
		"common" : "../common",
		"shopcookie" : "../shopcookie"
	}
})
require(["jquery","cookie","common","shopcookie"],function($,cookie,common,shopcookie){
	common.fn();
	shopcookie.fn();
	$("#list ul li").hover(function(){
		$(this).children("a").css("color","#008842");
		$(this).children("a").stop().animate({"padding-left":"14"},300);
	},function(){
		$(this).children("a").css("color","#000");
		$(this).children("a").stop().animate({"padding-left":"7"},300);
		return false;
	})
	$("#content_sort span").click(function(){
		$("#content_sort span").removeClass("opton");
		$(this).addClass("opton");
	})
	$.ajax({url : "../json/list.json", success : function(response){
		var json = response;
		for(var i = 0; i < json.length;i ++){
			var $content = $('<dl><dt><a href=""><img src=""/ class="picture"></a><span><h4></h4><h5>加入购物车</h5></span></dt><dd><h3><a href=""></a></h3><h2></h2></dd></dl>');
			$("#content").append($content);
			$content.find("img").attr({"src":json[i].src});
			$content.find("h3 a").html(json[i].name);
			$content.find("a").attr("href",json[i].links);
			$content.find("h2").html(json[i].price);
			$content.find("h4").html(json[i].information);
			$content.find("h5").attr("id",json[i].id);
			$content.find("h5").attr("price",json[i].price);
			$content.find("h5").click(function(){
				if($.cookie("product" + $(this).attr("id"))){
					var oCook = JSON.parse($.cookie("product" + $(this).attr("id")));
					$.cookie("product" + $(this).attr("id"),'{"id":"' + $(this).attr("id") + '","num":' + (oCook.num + 1) + ',"price":"' +  $(this).attr("price") + '","infor":"' + $(this).parent().parent().siblings().find("a").html() + '","img":"' + $(this).parent().siblings().children(".picture").attr("src") + '"}',{ expires: 7, path: '/' } );
				}else{
					$.cookie("product" + $(this).attr("id"),'{"id":"' + $(this).attr("id") + '","num":1'+ ',"price":"' +  $(this).attr("price") + '","infor":"' + $(this).parent().parent().siblings().find("a").html() + '","img":"' + $(this).parent().siblings().children(".picture").attr("src") + '"}',{ expires: 7, path: '/' } );
				}
				shopcookie.fn();
			})
			if(json[i].new == "true"){
				var $h6 = $("<h6></h6>");
				$content.append($h6);
			}
		}
	}})
})
